package com.liuguang.realgateway.service;

import com.liuguang.api.redis.RedisService;
import com.liuguang.common.enums.CommonResultEnum;
import com.liuguang.common.enums.RedisPreFixEnum;
import com.liuguang.common.pojo.CommonResult;
import com.liuguang.realgateway.utils.GatewayUtil;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @ClassName: ValidateCodeService
 * @Description：
 * @Author: wanghr
 * Date: 3:03 PM 2020/10/29
 * Version: 1.0
 */
@Component
public class ValidateCodeService {
    private static final Logger logger = LoggerFactory.getLogger(ValidateCodeService.class);



    @DubboReference
    private RedisService redisService;

    public Boolean validate(String codekey, String validateCode) {
        String key = RedisPreFixEnum.VERIFY_CODE_USERNAME_PASSWORD_TYPE.getValue() + codekey;
//            String key = RedisPreFixEnum.VALIDATE_CODE.getValue() +username;
        CommonResult<String> result = redisService.get(key);
        if (CommonResultEnum.SUCCESS.getCode().equals(result.getCode())
                && org.apache.commons.lang3.StringUtils.equals(validateCode, result.getData())) {
            logger.info("验证码验证成功");
            return true;
        }
        logger.info("验证码未获取到，或验证码不匹配");
        return false;
    }


}
